package assignment1.delegation;

public class Test {

	public static void main(String[] args) {
		Instance myInst = new Instance();
		Class prototype = new Class("prototype");
		myInst.instClass = prototype;
		myInst.instClass.dict.put("func1", new Function() { // add new function to class
					@Override
					public void execute() {
						System.out.println("test invoked");
					}
		});
		invoke(myInst, "func1");
		System.out.println("\n");
		
		Class extension = prototype.extension("extension");
		myInst.instClass = extension;
		invoke(myInst, "func1");

	}
		
	
	// lookup algorithm for methods
	public static void invoke(Instance obj, String func) {
		Function myFunc = obj.instClass.searchFunc(func);
		if (myFunc != null) {
			myFunc.execute();
			System.out.println(func);
		} else {
			System.out.println("ERROR");
		}
	}
}